var lineChart="";
var monthChart="";
var  yearChart="";
$(function(){
	refresh();
});

function refresh(){
	try{
	 allpsData();
	 lineData("/mobile/ridian","lineChart");
//	 endPullRefresh('#pudown');
	}catch(e){
	}
//	endPullRefresh("#pudown");
}

var chartsd = {};
var psid = param.psid;

function allpsData(){
	$.proAjax({
		url:"/mobile/psrealdata",
		data:{psid:psid},
		success: function (data){
			try{
				var psdatas= data.psRealData;
				for(var key in psdatas){
					if(psdatas[key]==null){
						$("#"+key).text("-");
					}else{
						if(typeof psdatas[key]=="number" && key!="rundate"){
							if(key=='acpower'){
								if(psdatas[key]>10000){
									$("#"+key).text((psdatas[key]/1000).toFixed(2));
									$("#"+key).next("span").text("MW");
								}else{
									$("#"+key).text((psdatas[key]).toFixed(2));
									$("#"+key).next("span").text("kW");
								}
							}else{
								if(psdatas[key]>10000){
									$("#"+key).text((psdatas[key]/10000).toFixed(2));
									$("#"+key).next("span").show();
								}else{
									$("#"+key).text((psdatas[key]).toFixed(2));
									$("#"+key).next("span").hide();
								}
							}
						}else if(key=="rundate"){
							$("#"+key).text(new Date(psdatas[key]).format("yyyy-MM-dd"));
						}else{
							$("#"+key).text(psdatas[key]);
						}
					}
				}
				//填充天气数据
				$("#psstateimg").attr("src",data.psstateimg);
				$("#psnormal").text(data.psnormal);
				$("#w-path").attr("src",data['w-path']);
				$("#citytemp").text(data.citytemp);
			}catch(e){	
			}
		}
	});
}
/**功率辐射曲线图*/
function lineData(url,id){
	$.proAjax({
		url:url,
		data:{psid:psid},
		success: function (data){
				var xdata = data.xdata;
				var acpower = data.acpower;
				var radian = data.ridian;
				var mychart = echarts.init(document.getElementById(id));
				chartsd[id] = mychart;
			 	//指定图表的配置项和数据
			 	 var option = {
			 	    tooltip: {
			 	    	show:true,
			 	        trigger: 'axis',
			 	       triggerOn:'mousemove'
			 	    },
			 	    legend: {
			 	    	itemWidth: 20,
			 	    	itemHeight: 5,
			 	    	borderRadius: 2,
			 	    	data:[{name:'功率',icon:'roundRect'},{name:'辐射强度',icon:'roundRect'}],
			 	    	top: 0,
			 	    	right: 20,
			 	    	textStyle: {
			 	    		color: '#9b9b9b'
			 	    	}
			 	    },
			 	    grid: {
			 	    	show: false,
			 	    	right: 35,
			 	    	left: 25,
			 	    	top: 50,
			 	    	bottom: 35,
			 	    	containLabel: true
			 	    },
			 	    xAxis:  {
			 	        type: 'category',
			 	        boundaryGap: true,
			 	        data: xdata,
			 	        axisLine: {
			 	            lineStyle: {
			 	            	color: '#9b9b9b',
			 	               	width:1
			 	            }
			 	        },
			 	        axisLabel: {
			 	    	    textStyle:{
			 	    		   color:'#9b9b9b'
			 	    	    }
			 	        },
			 	        axisTick: {
			 	    	  show: true
			 	        }
			 	    },
			 	    yAxis: [{
			 	        type: 'value',
			 	        name:'功率(kW)',
			 	        nameTextStyle: {
			    	    	color: '#9b9b9b'	
			    	    },
			 	        axisLine: {
			 	        	show: false,
			 	            lineStyle: {
			 	                color: '#9b9b9b',
			 	               	width:2
			 	            }
			 	        },
			 	        //标签颜色
			 	        axisLabel: {
			  	    	  textStyle:{
			  	    		   color:'#9b9b9b'
			  	    	   }
			  	        },
			 	        //隐藏分隔线
			 	       	splitLine: {
			 	       		show: false,
			 	       		lineStyle: {
			 	       			color: '#EEEEEE',
			 	       			width: 1,
			 	       			type: 'dashed'
			 	       		}
			 	       	},
			 	       	axisTick: {
			         	      show: true
			         	}
			 	    },
			 	    {
			 	    	type: 'value',
			 	        name:'辐射强度(W/m²)',
			 	        nameTextStyle: {
			 	    	 	color: '#9b9b9b'	
			 	     	},
			 	     	axisLine: {
			 	     		show: false,
			             	lineStyle: {
			            		color: '#9b9b9b',
				            	width:1
			             	}
			         	},
				        axisLabel: {
					    	textStyle:{
					    		color:'#9b9b9b'
					    	}
					       },
				 	    axisTick: {
				     	    show: false
				     	},
				     	splitLine: {
			 	       		show: true,
			 	       		lineStyle: {
			 	       			color: '#EEEEEE',
			 	       			width: 1,
			 	       			type: 'dashed'
			 	       		}
			 	       	},
			 	    }
			 	    ],
			 	    series: [
			 	        {
			 	           	name:'功率',
		 	            	type:'line',
			 	           	smooth: true,
			 	          	symbol: 'circle',
			 	          	symbolSize: 10,
			 	         	showSymbol: false,
			 	           	yAxisIndex: 0,
			 	            data:acpower,
		          	        itemStyle: {
		          	            normal: {
		          	                color: '#03ac46'
		          	            }
		          	        }
			 	        },
			 	        {
			 	            name:'辐射强度',
			 	            type:'line',
			 	           	smooth: true,
			 	           	symbol: 'emptyCircle',
			 	          	showSymbol: false,
			 	         	symbolSize: 10,
			 	           	yAxisIndex: 1,
			 	            data:radian,
			 	           	itemStyle: {
			     	            normal: {
			     	                color: '#0099e0'
			     	            }
			     	        }
			 	        }
			 	    ]
			 	};
			 	//使用刚指定的数据项和配置显示图表	
				  mychart.setOption(option);
				  mychart.resize();
		}
	});
}
/**电量柱状图*/
function barData(url,id){
	var mychart;
	$.proAjax({
		url:url,
		data:{psid:psid},
		success: function (data){
				var xdata = data.xdata;
				var ydata = data.ydata;
				var mychart = echarts.init(document.getElementById(id));
				 chartsd[id] = mychart;
			 	//指定图表的配置项和数据
			 	 var option = {
			 	    tooltip: {
			 	        trigger: 'axis'
			 	    },
			 	    legend: {
			 	    	itemWidth: 20,
			 	    	itemHeight: 5,
			 	    	borderRadius: 2,
			 	    	data:[{name:'电量',icon:'roundRect'}],
			 	    	top: 0,
			 	    	right: 20,
			 	    	textStyle: {
			 	    		color: '#9b9b9b'
			 	    	}
			 	    	
			 	    },
			 	   	grid: {
	           		    show: false,
	           		    top: 35,
			 	    	right: 40,
			 	    	left: 50,
	           	   	},
			 	    
			 	    xAxis:  {
			 	        type: 'category',
			 	        boundaryGap: true,
			 	        data: xdata,
			 	       	axisLine: {
			 	            lineStyle: {
			 	            	color: '#9b9b9b',
			 	               	width:1
			 	            }
			 	        },
			 	       axisLabel: {
			 	    	  textStyle:{
			 	    		   color:'#9b9b9b'
			 	    	   }
			 	       },
			 	       axisTick: {
			 	    	  show: false,
			 	          alignWithLabel: true
			 	        }
			 	       
			 	    },
			 	    yAxis: [{
			 	        type: 'value',
			 	        name:'发电量(kWh)',
			 	       	nameTextStyle: {
			    	    	color: '#9b9b9b'	
			    	     },
			 	       	axisLine: {
			 	            lineStyle: {
			 	                color: '#9b9b9b',
			 	               	width:1
			 	            }
			 	        },
			 	        //标签颜色
			 	       	axisLabel: {
			  	    	  textStyle:{
			  	    		   color:'#9b9b9b'
			  	    	   }
			  	       	},
			 	        //隐藏分隔线
			 	       	splitLine: {show: false},
			 	       	axisTick: {
			         	    show: false
			         	}
			 	    }
			 	    ],
			 	    series: [
			 	        {
			 	            name:'电量',
			 	            type:'bar',
			 	            data:ydata,
		          	        itemStyle: {
		          	            normal: {
		          	                color: '#19d3fb'
		          	            }
		          	        }
			 	        }
			 	    ]
			 	};
			 	//使用刚指定的数据项和配置显示图表	
				  mychart.setOption(option);
				  mychart.resize();
			}
		
	});
}

	mui("#segmentedControl").on("tap","a",function(){
		setTimeout(function() {
			var item = $(this).attr("href");
			 if(item=="#item1"){
				 lineData("/mobile/ridian","lineChart");
			 }else if(item=="#item2"){
				 barData("/mobile/daycapec","monthChart");
			 }else{
				 barData("/mobile/yearcapec","yearChart");
			 }
		}.bind(this), 100);
		 
	})




